package com.ss.android.newmedia.j;

import android.content.Context;
import android.os.Handler;

import com.bytedance.article.common.c.TTUtils;
import com.ss.android.common.AbsApiThread;
import com.ss.android.common.util.NetworkUtils;
import com.ss.android.http.legacy.a.NameValueImpl;
import com.ss.android.newmedia.MediaAppData;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public final class b extends AbsApiThread {
    private Context a;
    private String b;
    private Handler c;
    private boolean d;

    public b(Context arg2, Handler arg3, String arg4) {

        this.a = arg2;
        this.c = arg3;
        this.b = arg4;
        this.d = true;
    }

    public final void run() {
        int v1 = 18;
        int v0 = 1;
        int v8 = 10006;
        if (android.support.design.a.isTextEmpty(this.b)) {
            if (this.c == null) {
                return;
            }

            this.c.sendMessage(this.c.obtainMessage(v8, v1, 0));
            return;
        }

        if (this.a != null && !NetworkUtils.isNetworkAvailable(this.a)) {
            if (this.c != null) {
                this.c.sendMessage(this.c.obtainMessage(v8, 12, 0));
            } else {
            }

            return;
        }

        if (this.d) {
            v0 = 2;
        }

        String v5 = "http://ib.snssdk.com/service/1/collect_settings/";
        int v2 = 0;
        while (true) {
            if (v2 < v0) {
                try {
                    ArrayList v1_2 = new ArrayList();
                    ((List) v1_2).add(new NameValueImpl("data", this.b));
                    String v4 = NetworkUtils.executePost(8192, v5, ((List) v1_2));
                    v1 = 17;
                    if (android.support.design.a.isTextEmpty(v4)) {
                        v0 = v1;
                        break;
                    } else {
                        if (!isApiSuccess(new JSONObject(v4))) {
                            v0 = v1;
                        } else {
                            MediaAppData.provide().c(true);
                            if (this.c != null) {
                                this.c.sendMessage(this.c.obtainMessage(10005, this.b));
                            } else {
                            }
                            return;
                        }
                        break;
                    }
                } catch (Throwable v1_1) {
                    ++v2;
                    v1 = TTUtils.getErrorCode(this.a, v1_1);
                    continue;
                }
            } else {
                v0 = v1;
                break;
            }
        }
        if (this.c != null) {
            this.c.sendMessage(this.c.obtainMessage(v8, v0, 0));
        }
    }
}

